<template>
  <page-header-wrapper>
    <applicationSearch @search="handleSearch" @reset="handleReset"></applicationSearch>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <ellipsis :length="36" slot="ellipsis" slot-scope="text">{{ text || '/' }}</ellipsis>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <a-popconfirm placement="left" title="确定要腾退该房屋吗？" @confirm="handleVacated(record)">
            <y-button type="link" class="text-error">腾退</y-button>
          </a-popconfirm>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, applicationSearch } from '@/components'
import { getDistributionManagement } from '@/api/DistrictReviewReportManagement'
import { postUpdateReturnList } from '@/api/cityReviewAndManage'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    applicationSearch,
  },
  data() {
    return {
      queryParam: {
        Mode: 'ReturnManagement',
        strContent: {},
      },
      columns: [
        // {
        //   title: '序号',
        //   align: 'center',
        //   width: '80px',
        //   fixed: 'left',
        //   scopedSlots: { customRender: 'index' }
        // },
        {
          title: '申请编号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          fixed: 'left',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'IDCard',
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'Phone',
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'Name',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'RegionName',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '社区服务中心',
          align: 'center',
          dataIndex: 'TownshipName',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '房屋信息',
          align: 'center',
          customRender: (text, record) => {
            const { Roof, Unit, Floor, Number } = record
            return `${Roof}栋${Unit}单元${Floor}-${Number}`
          },
        },
        {
          title: '户型',
          align: 'center',
          dataIndex: 'Structure',
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'HouseMode',
        },
        {
          title: '操作',
          align: 'center',
          width: '140px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getDistributionManagement(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'districtDistributionVacatedManagementDetail',
        params: {
          id,
        },
      })
    },
    handleVacated(record) {
      this.$loading.show({
        tip: '提交中，请稍后...',
      })
      postUpdateReturnList({
        id: record.Esites,
        userid: this.$store.getters.userid,
      })
        .then((res) => {
          this.$message.success('房屋腾退成功成功')
          this.$refs.table.refresh()
        })
        .finally(() => {
          this.$loading.hide()
        })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
